﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Shop.Model.Custom {
    public class WebCart {
        protected static readonly object Lock = new object();
        protected static WebCart Instance = null;
        public static WebCart Self {
            get {
                lock (Lock) {
                    Instance = HttpContext.Current.Session["WebCart"] as WebCart;
                    if (Instance == null) {
                        Instance = new WebCart();
                        HttpContext.Current.Session["WebCart"] = Instance;
                    }

                    return Instance;
                }
            }          

        }


        private Customer _CurrentCustomer = null;

        public Customer CurrentCustomer {
            get {
                if (_CurrentCustomer == null)
                    _CurrentCustomer = new Customer {
                        Age = 0,
                        BirthDate = DateTime.Now,
                        City = "None",
                        Country = "None",
                        CustomerOrders = null,
                        FirstName = "Anonymous",
                        IdCustomer = 0,
                        LastName = "Anonymous",
                        Street = "None",
                        Zip = "None"
                    };

                return _CurrentCustomer; }
            set {
                _CurrentCustomer = value;
            }
        }

        public bool IsLoggedIn { get {
                return CurrentCustomer.IdCustomer > 0;
        } }

        public CustomerOrder CustomerOrder { get; set; }
        public List<OrderItem> OrderItem { get; set; }

        public void Reset() {
            CustomerOrder = new CustomerOrder();
            OrderItem = new List<OrderItem>();
        }
    }
}
